package com.etonedu.meals.base;

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.blankj.utilcode.util.LogUtils;
import com.etonedu.meals.BuildConfig;
import com.etonedu.meals.bean.MyObjectBox;

import org.xutils.x;

import io.objectbox.BoxStore;
import io.objectbox.android.AndroidObjectBrowser;

public class BaseApplication extends Application {
    private BoxStore boxStore;
    @Override
    public void onCreate() {
        super.onCreate();

        CrashHandler crashHandler = CrashHandler.getInstance();
        crashHandler.init(getApplicationContext());

        x.Ext.init(this);
        initObjectBox();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }

    private void initObjectBox() {

        boxStore = MyObjectBox.builder().androidContext(this).build();

        if (BuildConfig.DEBUG) {
            LogUtils.d("BaseApplication", String.format("Using ObjectBox %s (%s)",
                    BoxStore.getVersion(), BoxStore.getVersionNative()));
            AndroidObjectBrowser browser = new AndroidObjectBrowser(boxStore);
            boolean isStart = browser.start(this);
            LogUtils.e("isStart = "+isStart);
        }
    }

    public BoxStore get() {
        return boxStore;
    }

}
